/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gray.swing.field;

import gray.Field;
import snippet.Snipet;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.KeyEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 *
 * @author martin
 */
public class BigTextField extends JPanel implements Field<String,Container>{
    private final JLabel _label;
    private final JTextArea textArea;
    
    private BigTextField(final Snipet lang,final String name, final Character key){
        super(new BorderLayout());
        textArea = new JTextArea();
        _label = new JLabel(name);
        _label.setDisplayedMnemonic(KeyEvent.getExtendedKeyCodeForChar(key));
        _label.setLabelFor(textArea);
        JScrollPane scrollPane = new JScrollPane(textArea,
                               JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                               JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        add(_label);
        add(scrollPane,BorderLayout.CENTER);

    }
    
    public static Field<String,Container> factory(final Snipet lang,final String name, final Character key){
        return new BigTextField(lang,name,key);
    }

    @Override
    public String input() {
        return textArea.getText();
    }

    @Override
    public Container container() {
        return this;
    }
    
    @Override
    public Boolean ready() {
        return true;
    }
}
